﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SubTitleConvertors.Movies
{
    class SubDownload
    {
    }
}

/*
 * Please leave this Copyright notice in your code if you use it
 * Written by Decebal Mihailescu [http://www.codeproject.com/script/articles/list_articles.asp?userid=634640]
 */
namespace TextExtractors
{
    using System;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.ComponentModel.Composition;
    using CommonUtils;

    [Export(typeof(ITextImport))]
    [ExportMetadata("IsMovie", true)]
    [ExportMetadata("Description", "Movie files")]
    [ExportMetadata("FileExtension", "*.mkv; *.avi; *.mp4")]
    [ExportMetadata("ContextMenuText", "&Download Subtitle")]
    [ExportMetadata("IconName", @"internet.ico")]
    public class SubDownload : ITextImport
    {

        #region ITextImport Members

        public string GetAllTextFromFile(string fileName, out Encoding encoding)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(null, "fileName");
            }
            if (!File.Exists(fileName))
            {
                throw new ArgumentException("File '" + fileName + "' is not found");
            }
            string str = string.Empty;
            try
            {
                var arg = new ProgressEventArgs();
                arg.Description = "Opening txt file";
                arg.Progress = 0;
                if (ProgressChanged != null && ProgressChanged.GetInvocationList().Length > 0)
                    ProgressChanged(this, arg);
                using (StreamReader reader = new StreamReader(fileName, true))//GetEncoding(0x4e3)))
                {
                    encoding = reader.CurrentEncoding;
                    return reader.ReadToEnd();
                }
            }
            catch (Exception exception)
            {
                throw new Exception("Error during text extraction from Text-file: " + fileName + Environment.NewLine + exception.Message);
            }
            //return str;
        }


        public event EventHandler ProgressChanged;
        #endregion
    }
}


